package com.zhike.b2b.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.saas.struts.form.LoginForm;
import com.saas.sys.bpm.TradeCheckIntf;
import com.saas.sys.bpm.TradeLoggerIntf;
import com.saas.sys.bpm.TradeRegIntf;
import com.saas.sys.buffer.Buffers;

//定义URL映射对应/user/user.action
//定义名为reload的result重定向到user.action, 其他result则按照convention默认.
public class AutoLoginAction 
{
	private LoginForm loginForm;
	private TradeRegIntf tri;
	private TradeCheckIntf tci ;
	
	private Logger localLogger = LoggerFactory.getLogger(AutoLoginAction.class);
	
  public String execute(HttpServletRequest request)
  {
    Buffers localBuffers1 = new Buffers();
    Buffers localBuffers2 = new Buffers();
    Buffers localBuffers3 = new Buffers();
    Buffers localBuffers4 = new Buffers();
    
    ArrayList localArrayList1 = new ArrayList();
    ArrayList localArrayList2 = new ArrayList();
    
    HttpSession session = request.getSession();
    localBuffers1.convert(request, loginForm, session);
    tci.execTradeCheck(localBuffers1);
    localBuffers3 = tci.getOutBuffer();
    ArrayList localArrayList3 = localBuffers3.buffersToBuffer(localBuffers3);
    if (localBuffers3.getInt("RESULT_CODE") != 0)
    {
    	request.setAttribute("outBuffer", localBuffers3);
    	request.setAttribute("backQ", localArrayList3);
      return localBuffers3.getString("ERROR_FWD");
    }
    localBuffers2 = tri.tradeRegInfo(localBuffers1);
    int i = 0;
    if (localBuffers2.getString("COOKIETIME") != null)
      i = Integer.parseInt(localBuffers2.getString("COOKIETIME"));
    ArrayList localArrayList4 = new ArrayList();
    localArrayList4 = localBuffers2.getSessionList();
    Iterator it = localArrayList4.iterator();
    while (it.hasNext())
    {
      HashMap localObject2 = (HashMap)it.next();
      if (localObject2.get("name") != null && (localObject2.get("name") != ""))
      {
        String localObject3 = localBuffers2.getString(localObject2.get("name").toString());
        session.setAttribute(localObject2.get("name").toString(), localObject3);
      }
    }
    String success = localBuffers2.getString("SUCCEED_FWD");
    String error = localBuffers2.getString("ERROR_FWD");
    localLogger.info("业务登记结束！");
    if (localBuffers2.getInt("RESULT_CODE") == 0)
    {
      localLogger.info("开始记录业务日志......");
      tri.setCheck_tag("1");
      localBuffers4 = tri.tradeRegInfo(localBuffers2);
      localLogger.info("业务日志记录结束！");
    }
    localLogger.info("开始设置返回数据.......");
    ArrayList localObject3 = localBuffers2.buffersToBuffer(localBuffers2);
    request.setAttribute("backQ", localObject3);
    localLogger.info("全部业务结束，转向表示层！");
    if (localBuffers2.getInt("RESULT_CODE") == 0)
      return success;
    return error;
  }

	public LoginForm getLoginForm() {
		return loginForm;
	}

	public void setLoginForm(LoginForm loginForm) {
		this.loginForm = loginForm;
	}

	public TradeRegIntf getTri() {
		return tri;
	}

	public void setTri(TradeRegIntf tri) {
		this.tri = tri;
	}

	public TradeCheckIntf getTci() {
		return tci;
	}

	public void setTci(TradeCheckIntf tci) {
		this.tci = tci;
	}
	
	
}

